<template>
	<view class="leave-examine">
		<nav-tabs-leave
			:defaultIndex="defaultIndex"
			@attedanceChange="attedanceChange"
			:attedanceOptions="attedanceOptions"
			:periodValue="periodValue"
			:tapsData="tapsData"
			:isShowType ="false"
			@tapChange="clickTabs"
		></nav-tabs-leave>
		<view v-if="defaultIndex == 0" class="has-examine">
			<view v-if="leaveListData.length == '0'" class="data-tip">当前没有任何数据</view>
			<view v-if="leaveListData.length != '0'">
				<view v-for="(item, index) in leaveListData" class="leave-card" :key="index">
					<merits-examine-card :leaveData="item" @adopt="adopt(item)" @exit="exit(item)" @handleClick="jumpLeaveDetail(item)" :isBtn="isShowBtn"></merits-examine-card>
				</view>
			</view>
		</view>
		<assign-module billtype="WAMP"
						@finishExamine="finishService" 
						:formPk="nowItemPk" 
						ref="assignCharacter" >
		</assign-module>
		<view v-if="defaultIndex == 1" class="examine-inforn">
			<view v-if="leaveListData.length == '0'" class="data-tip">当前没有任何数据</view>
			<view class="roval-list" v-if="leaveListData.length != '0'">
				<view v-for="(item, index) in leaveListData" :key="index">
					<approval-merits-exa
						:status="item.data.hvo.approvestatus == '驳回' ? '2' : '1'"
						:leaveData="item"
						@handleClick="clickRoval(item)"
						@exitExa="exitExa(item.billid)"
					></approval-merits-exa>
				</view>
			</view>
		</view>
		<sendNews ref="sendNews" @confirm="confirm" :status="examineStatus"></sendNews>
	</view>
</template>

<script>
import service from '../../../common/service/new_file.js';
import apiData from '../../../common/utils/apiData.js';
import utils from '../../../common/utils/utils.js';
import meritsExamineCard from "../components/merits-examine-card.vue"
import approvalMeritsExa from "../components/approval-merits-exa.vue"
export default {
	data() {
		return {
			examineStatus: '',
			attedanceOptions: [],
			periodValue: '期间',
			defaultIndex: 0,
			tapsData: [{ value: '未审核', num: 0 }, { value: '已审核', num: 0 }],
			leaveListData: [],
			navForm: {
				pk_leavetype: '',
				pk_period_b: ''
			},
			isCheck: 'N',
			nowItemPk:'', //当前选择的项
			spr: [] ,//指派人
			isShowBtn:0,
			state:2,//2查看审批，0查看自己
		};
	},
	components:{
		meritsExamineCard,
		approvalMeritsExa
	},
	methods: {
		clickRoval(e) {
			this.nowItemPk = e.billid
			uni.navigateTo({
				url: '../meritsDetail/meritsDetail?item=' + JSON.stringify(e)+'&pk='+this.nowItemPk+'&isShowBtn='+'0'
			});
		},
		attedanceChange(value) {
			this.periodValue = value.yearmth;
			this.navForm.pk_period_b = value.yearmth.replace("-","");
			this.getLeaveList();
		}, //期间
		jumpLeaveDetail(e) {
			this.nowItemPk = e.billid
			uni.navigateTo({
				url: '../meritsDetail/meritsDetail?item=' + JSON.stringify(e)+'&pk='+this.nowItemPk+'&isShowBtn='+'1'+'&isExa=1'
			});
		},
		finishService(){
			this.getLeaveList();
		},
		exitExa(pk) {
			//撤回
			let _this = this;
			let data = apiData.setExitExamineData(pk, 'WAMP'); //FN(billtype, isAdopt,pk)
			service.common(data, {
				success: function(res) {
					setTimeout(() => {
						uni.showToast({
							title: '已撤回'
						});
					}, 100);
					_this.getLeaveList();
				},
				fail: function(err) {},
				all: function(all) {}
			});
		},
		adopt(item) {
			this.nowItemPk = item.billid
			this.$refs.assignCharacter.init('1',this.nowItemPk)
		},
		exit(item) {
			this.nowItemPk = item.billid
			this.$refs.assignCharacter.init('2',this.nowItemPk)
		},
		clickTabs(e) { 
			this.defaultIndex = e.index;
			this.leaveListData = [];
			if (e.index == '0') {
				this.isCheck = 'N';
				this.getLeaveList();
			} else if (e.index == '1') {
				this.isCheck = 'Y';
				this.getLeaveList();
			}
		},
		getLeaveList() {
			let _this = this;
			let head = {
				pk_leavetype: this.navForm.pk_leavetype,
				pk_period_b: this.navForm.pk_period_b
			};
			let data = apiData.setLeaveListData('WAMP', this.isCheck, head,this.state);
			service.common(data, {
				success: function(res) {
					if (res.data.VALUES.length == 0) {
						uni.showToast({
							icon: 'none',
							title: '未查询到数据'
						});
					}
					_this.leaveListData = res.data.VALUES;
					if (_this.isCheck == 'N') {
						_this.tapsData[0].num = _this.leaveListData.length;
					} else if (_this.isCheck == 'Y') {
					}
				}
			});
		}
	},
	onLoad(obj) {
		this.isShowBtn = obj.isShowBtn
		if(obj.state){
				this.state =obj.state
		}
		this.getLeaveList();
		this.attedanceOptions = JSON.parse(uni.getStorageSync('workPeriod'));
		this.attedanceOptions.unshift({
			pk_period: '',
			pk_period_b: '',
			yearmth: '全部'
		});
	},
	onPullDownRefresh() {
		this.getLeaveList();
	}
};
</script>

<style lang="scss" scoped>
.head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 30rpx;
	padding-top: 120rpx;
	.search-btn {
		font-size: 28rpx;
		padding-left: 10rpx;
	}
	.search {
		flex: 1;
	}
}

.has-examine {
	padding-top: 80rpx;
	padding-bottom: 40rpx;
}
.examine-inforn {
	padding-top: 80rpx;
	padding-bottom: 40rpx;
}
.data-tip {
	padding-top: 100rpx;
	text-align: center;
	color: #949494;
	font-size: 28rpx;
}
.roval-list {
	padding: 20rpx 36rpx;
}
.leave-card {
	margin: 40rpx 0;
}
.date {
	padding: 0 36rpx;
	margin-top: 20rpx;
	font-size: 16px;
	font-weight: 600;
	color: #121f2c;
}
</style>
